package com.example.XueCuApp.Base;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.XueCuApp.Utils.SPUtil;
import com.example.XueCuApp.Utils.StringUtil;
import com.example.XueCuApp.Utils.TimeUtil;
import com.example.XueCuApp.wight.LosLoadDialog;

import java.util.HashMap;
import java.util.Map;

public abstract class BaseActivity extends AppCompatActivity {

    public LosLoadDialog iosLoadDialog;
    public String BaseUrl;
    public Map<String, String> headers;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        makeStatusBarTransparent(this);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(initLayoutId());
        initView();
        initData();

        if (iosLoadDialog == null) {
            //初始化菊花
            iosLoadDialog = new LosLoadDialog(this);
        }

        //获取headmap
        if (headers == null) {
            headers = new HashMap<>();
        }

        // 雪厨 只有登录需要 head 当前时间
        headers.put("requestTime", TimeUtil.getLocationTimeNew(TimeUtil.FORMAT_TIME_EN));

//        String token = (String) SPUtil.get(this, BaseConfig.JJH_TOKEN, "");
//        if (!StringUtil.isNullOrEmpty(token)) {
//            headers.put("Token", token);
//        }


    }


    public abstract int initLayoutId();

    protected abstract void initView();

    protected abstract void initData();

    @Override
    protected void onResume() {
        super.onResume();
        BaseUrl = (String) SPUtil.get(this, BaseConfig.Base_URL_STRING, "");
    }

    public static void makeStatusBarTransparent(Activity activity) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            return;
        }
        Window window = activity.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            int option = window.getDecorView().getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
            window.getDecorView().setSystemUiVisibility(option);
            window.setStatusBarColor(Color.TRANSPARENT);
        } else {
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }
}
